﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AutoGear.BLL;
using Ext.Net;
using ECommerce.Library.DataStructure;
using eShop.Model;
using eShop.Business;

public partial class admin_manufacturer_list : SiteAdminBasePage
{
    //private bool _useSearch
    //{
    //    get
    //    {
    //        if (Session["_useSearch"] == null)
    //            return false;
    //        else return Convert.ToBoolean(Session["_useSearch"]);
    //    }
    //    set
    //    {
    //        Session["_useSearch"] = value;
    //    }
    //}

    protected void Page_Load(object sender, EventArgs e)
    {
        uccResponseMessage.Visible = false;

        //if (!X.IsAjaxRequest)
        //{
        //    //Session["_useSearch"] = null;
        //}
    }
    protected void Store1_RefreshData(object sender, StoreRefreshDataEventArgs e)
    {
        BindSupplier(e.Sort + (e.Dir.ToString() == "Default" ? "" : " " + e.Dir), e.Start, e.Limit);
    }

    protected void imgSearchButton_Click(object sender, EventArgs e)
    {

    }

    private void BindSupplier(string sort, int start, int limit)
    {
        ReadWriteCustomCollection<Manufacturer> data = null;
        int totalCount = 0;
        if (String.IsNullOrEmpty(sort))
            sort = "ProductBrandId";
        data = ManufacturerManager.GetBackendBrandList(sort, start, limit);
        totalCount = ManufacturerManager.GetBackendBrandListCount();

        Store1.DataSource = data;
        Store1.DataBind();

        (Store1.Proxy[0] as PageProxy).Total = totalCount;
    }

    [DirectMethod(Namespace = "Polana.WebService")]
    public void UpdateSupplier(int id, string supplierName, string description, bool isActive)
    {
        Manufacturer supplier = ManufacturerManager.GetById(id);
        supplier.BrandName = supplierName;
        supplier.BrandDescription = Server.HtmlEncode(description);
        supplier.IsActive = isActive;
        ManufacturerManager.Update(supplier);
        //GridPanel1.Store.Primary.DataBind();
        Store1.DataBind();
    }

    [DirectMethod(Namespace = "Polana.WebService")]
    public void DeleteSupplier(string ids)
    {
        ids = ids.TrimStart(' ');
        string[] idArray = ids.Split(' ');
        List<int> idList = new List<int>();
        foreach (string id in idArray) idList.Add(Convert.ToInt32(id));
        ManufacturerManager.DeleteBrands(idList);
        Store1.DataBind();
    }

    //[DirectMethod(Namespace = "Polana.WebService")]
    //public void SearchSupplier()
    //{
    //    _useSearch = true;
    //    Store1.DataBind();
    //}
}